package com.bawei.module_live.ui.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bawei.module_live.data.LiveShopData
import com.bawei.module_live.databinding.ItemGoodsBinding
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bawei.module_live.data.Record
import com.google.gson.GsonBuilder

class LiveShopAdapter(private val list: List<Record>) : RecyclerView.Adapter<LiveShopAdapter.ViewHolder>() {
    inner class ViewHolder(val binding: ItemGoodsBinding) : RecyclerView.ViewHolder(binding.root)
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val binding = ItemGoodsBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return ViewHolder(binding)
    }
    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val item = list[position]
        holder.binding.tvGoodsName.text = item.title
        holder.binding.tvGoodsPrice.text = "￥${item.purchasePrice}"
        Glide.with(holder.binding.ivGoodsIcon)
            .load(item.mainImgUrl)
            .centerCrop()
            .into(holder.binding.ivGoodsIcon)
    }
    override fun getItemCount() = list.size
}